unit CadAnomalia2;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Template, AppEvnts, DB, Buttons, ComCtrls, ToolWin, StdCtrls,
  Mask, DBCtrls, JvExControls, JvComponent, JvDBLookup, ExtCtrls, Menus;

type
  TFormCadAnomalia2 = class(TFormTemplate)
    Panel1: TPanel;
    Label1: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    Label6: TLabel;
    Label7: TLabel;
    Label8: TLabel;
    SpeedButton4: TSpeedButton;
    Label13: TLabel;
    SpeedButton2: TSpeedButton;
    DBEdit1: TDBEdit;
    DBEdit3: TDBEdit;
    DBEdit4: TDBEdit;
    DBEdit5: TDBEdit;
    DBEdit6: TDBEdit;
    DBEdit7: TDBEdit;
    DBEdit8: TDBEdit;
    JvDBLookupComboVeiculo: TJvDBLookupCombo;
    DBEdit13: TDBEdit;
    JvDBLookupComboMotorista: TJvDBLookupCombo;
    procedure dsPrincipalStateChange(Sender: TObject);
    procedure btnAbrirClick(Sender: TObject);
    procedure btnPesquisarClick(Sender: TObject);
    procedure SpeedButton4Click(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure SpeedButton2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  FormCadAnomalia2: TFormCadAnomalia2;

implementation

uses DM, Geralsis, Abrir, Pesquisa, Principal, DMS, Geral;

{$R *.dfm}

procedure TFormCadAnomalia2.dsPrincipalStateChange(Sender: TObject);
begin
  inherited;
    if (Sender as tdatasource).dataset.State in [dsEdit,dsInsert] then
    begin
        DBEdit5.ReadOnly := true;
        DBEdit6.ReadOnly := true;
        if USUARIOCORRENTE <> USUARIOPRINC then
        begin
            DBEdit4.ReadOnly := true;
            DBEdit3.ReadOnly := true;
            DBEdit7.ReadOnly := true;
        end;
        if (((Sender as tdatasource).dataset.State = dsEdit) and (dsPrincipal.DataSet.FieldByName('DATASTOP').IsNull)) then
            dsPrincipal.DataSet.FieldByName('DATASTOP').AsDateTime := now;
    end;
end;

procedure TFormCadAnomalia2.btnAbrirClick(Sender: TObject);
begin
  inherited;
    FormAbrir.Mostrar(DMprinc.QueryAnomalia2,'CODANOMALIA');
    FreeAndNil(FormAbrir);
end;

procedure TFormCadAnomalia2.btnPesquisarClick(Sender: TObject);
var
     RespFiltro: String;
     RespCombo : String;
begin
  inherited;
    RespFiltro :=  MetodosGer.OpenFiltro('VEICULO;', 1, false);
    if RespFiltro <> '-1' then
    begin
        if GetFiltro(RespFiltro, 3) > 0 then
        begin
            dsPrincipal.DataSet.Filtered := False;
            dsPrincipal.DataSet.Filter := 'codveiculo ='+inttostr(GetFiltro(RespFiltro, 3));
            dsPrincipal.DataSet.Filtered := True;
        end;
    end;
    FormPesquisa.Mostrar('Pesquisa' , 'codanomalia' , Dmprinc.QueryAnomalia2 ,
                        'DataStart;DataStart;DataStop;DataStop;Codigo;CodAnomalia;');
    FreeAndNil(FormPesquisa);
    dsPrincipal.DataSet.Filtered := False;
end;

procedure TFormCadAnomalia2.SpeedButton4Click(Sender: TObject);
begin
  inherited;
    CadastroNewCombo(FormPrincipal.Veiculo1 , JvDBLookupComboVeiculo );
end;

procedure TFormCadAnomalia2.FormShow(Sender: TObject);
begin
    SetaDataset(dsPrincipal,DMprinc.QueryAnomalia2);
  inherited;

end;

procedure TFormCadAnomalia2.SpeedButton2Click(Sender: TObject);
begin
  inherited;
    CadastroNewCombo(FormPrincipal.Motorista1 , JvDBLookupComboMotorista);
end;

end.
